package c2.group.business.tb.ps;


import c2.group.business.tb.TBSubModule;
import cate.game.play.part.PlaySide;
import cate.game.pvp.throne.data.ps.TBPlaySide;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@NoteClass("王座争霸-阵容库")
public class TBPlaySideModule extends TBSubModule {

	@NoteField("玩家playSide")
	public Map<String, TBPlaySide> psMap = new HashMap<>();

	public void readFromBD() {
		for (TBPlaySide ps : useDb().tb.getPlySide()) {
			psMap.put(ps.playSide.snapshot.uid, ps);
		}
	}

	public void save() {
		useDb().tb.savePlaySide(new ArrayList<>(psMap.values()));
	}

	public void clear(){
		psMap.clear();
	}

	@Override
	public void onEnterNewSeason() {

	}

	@Override
	public void onPeriodChange(byte period) {

	}


	public void setPlaySide(PlaySide playSide) {
		if (playSide == null) {
			return;
		}
		psMap.put(playSide.snapshot.uid, new TBPlaySide(playSide));
	}

	public PlaySide getPlaySide(String uid) {
		TBPlaySide tbPlaySide = psMap.get(uid);
		return tbPlaySide != null ? tbPlaySide.playSide : null;
	}
}
